﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO = Viewer.BusinessObject.BusinessEntities;
using Ext.Net;
namespace Viewer.ToChuc.UserControls
{
    public partial class UCLookUpDiaChi : System.Web.UI.UserControl
    {
        BO.CommonCode common = new Viewer.BusinessObject.BusinessEntities.CommonCode();
        BO.DiaChi query = new Viewer.BusinessObject.BusinessEntities.DiaChi();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void ShowDialogDiaChi()
        {
            storeTinh.DataSource = common.LoadToChucHanhChinhByLoai(1242);
            storeTinh.DataBind();

            storeDiachi.DataSource = query.LoadAllDataForDiachi();
            storeDiachi.DataBind();
            wdDiaChi.Show();

        }

        protected void BtnReset_Click(object sender, DirectEventArgs e)
        {
            txtThonPho.Text = string.Empty;
            txtSoNha.Text = string.Empty;
            cbbQuan.SelectedItem.Value= string.Empty;
            cbbTinh.SelectedItem.Value = string.Empty;
            cbbXa.SelectedItem.Value = string.Empty;
            X.Mask.Hide();
        }
        protected void BtnSearch_Click(object sender, DirectEventArgs e)
        {
            int xa = !string.IsNullOrEmpty(cbbXa.SelectedItem.Value) ? Convert.ToInt16(cbbXa.SelectedItem.Value) : 0;
            int quanHuyen = !string.IsNullOrEmpty(cbbQuan.SelectedItem.Value) ? Convert.ToInt16(cbbQuan.SelectedItem.Value) : 0;
            int thanhPho = !string.IsNullOrEmpty(cbbTinh.SelectedItem.Value) ? Convert.ToInt16(cbbTinh.SelectedItem.Value) : 0;
            storeDiachi.DataSource = query.LoadDataByCondition(txtSoNha.Text, xa, txtThonPho.Text, quanHuyen, thanhPho);
            storeDiachi.DataBind();
            X.Mask.Hide();
        }
        [DirectMethod]
        public void DialogDiaChi(string type, int diachiId)
        {
            if (type.Equals("AddNew"))
            {
                UCDiaChi.Show(type, 0);
            }
            else if (type.Equals("Delete"))
            {
                BO.DiaChi query = new Viewer.BusinessObject.BusinessEntities.DiaChi();
                query.DeleteDiaChi(diachiId);
                ShowDialogDiaChi();
            }
            else
            {
                UCDiaChi.Show(type, diachiId);
            }
            X.Mask.Hide();
        }
        [DirectMethod]
        public void LoadQuan(int key, string type)
        {
            if (type.Equals("Quan"))
            {
                storeQuan.DataSource = common.LoadToChucHanhChinhByToChucCha(key);
                storeQuan.DataBind();
                cbbQuan.Text = string.Empty;
                cbbXa.Text = string.Empty;
            }
            else if (type.Equals("Xa"))
            {
                storeXa.DataSource = common.LoadToChucHanhChinhByToChucCha(key);
                storeXa.DataBind();
                cbbXa.Text = string.Empty;
            }

        }
    }
}